package com.report.service.impl;

import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.report.entity.ReportFileTag;
import com.report.mapper.ReportFileTagMapper;
import com.report.service.ReportFileTagService;
import com.zmh.framework.constants.Constants;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author summer
 * @date 2024-06-26 12:15
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ReportFileTagServiceImpl extends ServiceImpl< ReportFileTagMapper, ReportFileTag>  implements ReportFileTagService {

    @Override
    public void saveSpecialTagList(String tagName, Integer id) {
        this.remove(Wrappers.lambdaQuery(ReportFileTag.class).eq(ReportFileTag::getReportFileId, id));
        if (StrUtil.isNotEmpty(tagName)) {
            String[] tagList = tagName.split(Constants.COMMA);
            List<ReportFileTag> tags = ListUtil.list(true);
            for (String tag : tagList) {
                ReportFileTag reportFileTag = new ReportFileTag();
                reportFileTag.setReportFileId(id);
                reportFileTag.setName(tag);
                tags.add(reportFileTag);
            }
            this.saveBatch(tags);
        }
    }
}
